package com.qiusuo0226.platform.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiusuo0226.common.constant.NumConstant;
import com.qiusuo0226.platform.mapper.SysVersionMapper;
import com.qiusuo0226.platform.pojo.po.SysVersionPO;
import com.qiusuo0226.platform.service.SysVersionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统版本数据处理层 接口实现
 * @author qiusuo
 * @date 2024/3/15 9:56
 */
@Slf4j
@Service
public class SysVersionServiceImpl extends ServiceImpl<SysVersionMapper, SysVersionPO> implements SysVersionService {


    @Override
    public boolean versionExist(String version, int order) {
        List<SysVersionPO> sysVersionPOList = baseMapper.versionExist(version, order);
        // 版本和排序 或 排序序号 是否存在
        return CollectionUtil.isNotEmpty(sysVersionPOList);
    }

    @Override
    public boolean addVersion(String version, int order, String developer, String[] description) {

        SysVersionPO sysVersionPO = new SysVersionPO();
        sysVersionPO.setExecuteVersion(version);
        sysVersionPO.setSortNum(order);
        sysVersionPO.setDeveloper(developer);
        sysVersionPO.setDescription(String.join("::", description));

        return baseMapper.insert(sysVersionPO) > NumConstant.N0;
    }
}
